// 获取页面数据
var resData = '';
// 填充头像选择列表
$('#id_head_pic_list').html(function (){
	var str       = '';
	var pic       = '';
	var bindClass = '';
	for(var i = 1; i <= 102; i++){
		pic       = 'static/images/head_pic/1_(' + i + ').jpg';
		bindClass = 'tag_head_picitem';
		if(pic == $('#id_userInfo_headpic').attr('src')){
			bindClass = '';
		}
		str = '<a class="' + bindClass + '" amv="' + i + '"><img src="' + pic + '" class="headImg"></a>';
		$(this).append(str);
	}
});

$('#id_select_head').on('click', '', function (){
	$('#id_user_headpic').attr('src', $('#id_userInfo_headpic').attr('src'));
	$('#id_head_pic_choice').show();
})
$('#id_close_choice,#id_setpic_cannel').on('click', '', function (){
	$('#id_head_pic_choice').hide();
})
$('#id_head_pic_list').on('click', '.tag_head_picitem', function (){
	var picUrl = 'static/images/head_pic/1_(' + $(this).attr('amv') + ').jpg';
	$('#id_user_headpic').attr('src', picUrl);
	$('#id_user_headpic').attr('amv', $(this).attr('amv'));
})



$('#id_setpic_post').on('click', '', function (){
	// 点击一次
//	$(this).unbind('click');
	// 提交用户修改头像请求
	var pid = parseInt($('#id_user_headpic').attr('amv'));
	if(pid < 0 || isNaN(pid)){
		showMsg('温馨提示', '请选择头像');
		return;
	}
	$.ajax({  
		type:'post',    
	    url: setHeadPic,  
	    data:'operation=setpic&pid=' + $('#id_user_headpic').attr('amv'),  
	    cache:false,  
	    dataType:'json',  
	    success:function(res){  
	    	if(res.status == 'success'){
	    		showMsg('温馨提示', '修改成功', 'reload');
	    	}else{
	    		var msg = '网络错误，请刷新页面重试';
	    		if(res.msg){
	    			msg = res.msg;
	    		}
	    		showMsg('温馨提示', msg);
	    	}
	    }  
	})
})

function showMsg(title, content, reload=''){
	layer.open({
        title: title,
        content: content,
        className: 'layui-m-tag-msg',
        btn: ['确定'],
        yes: function (index){
			// 继续投注
        	layer.close(index);
        	if(reload){
        		window.location.reload();
        	}
        },
    });
}